package cn.tedu.kaifanlav1.user.service.impl;


import cn.tedu.kaifanlav1.user.mapper.UserMapper;
import cn.tedu.kaifanlav1.user.pojo.dto.FoodParam;
import cn.tedu.kaifanlav1.user.pojo.dto.UserQuery;
import cn.tedu.kaifanlav1.user.pojo.dto.UserSaveParam;
import cn.tedu.kaifanlav1.user.pojo.entity.User;
import cn.tedu.kaifanlav1.user.pojo.vo.UserVO;
import cn.tedu.kaifanlav1.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@Slf4j
/* 业务层实现类上要加@Service注解,表示该类是业务层实现类 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public List<UserVO> selectUser(UserQuery userQuery) {
        log.debug("查询用户业务:userQuery={}",userQuery);
        List<UserVO> list = userMapper.selectUser(userQuery);
        return list;
    }

    @Override
    public void saveUser(UserSaveParam userSaveParam) {
        User user = new User();
        BeanUtils.copyProperties(userSaveParam,user);
        if (user.getId()==null){
            user.setCreateTime(new Date());
            userMapper.insert(user);
        }
    }

    @Override
    public void delectFood(Long id) {
        log.debug("删除菜品业务:foodId={}",id);
        userMapper.delectFood(id);
    }

    @Override
    public void insertFood(Long id) {
        log.debug("添加菜品:FoodId={}",id);
        userMapper.insertFood(id);
    }
}
